"""
仪表盘类
"""

from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class DashboardPage(BasePage):

    # 点击添加组件定位器
    add_module_locator = (By.ID, "add")
    # 组件名定位器
    module_name_locator = (By.ID, "title")
    # 选择组件定位器
    choice_locator = (By.NAME, "widget")
    # 销售漏斗
    sale_locator = (By.LINK_TEXT, "销售漏斗")
    # 点击保存
    save_locator = (By.NAME, "submit")
    # 添加组件成功信息提示
    success_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 点击更多
    more_locator = (By.CLASS_NAME, "dropdown-toggle")
    # 点击日志
    log_locator = (By.LINK_TEXT, "日志")
    # 点击头像，弹出弹窗
    admin_locator = (By.CSS_SELECTOR,"body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul.nav.pull-right > li:nth-child(6) > a > img")
    # 点击操作日志
    operation_log_locator = (By.LINK_TEXT, "操作日志")
    # 点击权限分配
    poverty_locator = (By.LINK_TEXT, "权限分配")
    # 点击组织架构
    organization_locator = (By.LINK_TEXT, "组织架构")
    # 点击个人资料
    personal_data_locator = (By.LINK_TEXT, "个人资料")
    # 点击站内信
    message_locator = (By.LINK_TEXT, "站内信")

    def add_module(self):
        """点击添加组件"""
        self.driver.find_element(*self.add_module_locator).click()

    def input_module_name(self,module_name):
        """输入组件名"""
        self.driver.find_element(*self.module_name_locator).send_keys(module_name)

    def choice(self,index=1):
        """选择组件"""
        choice_element = self.driver.find_element(*self.choice_locator)
        select = Select(choice_element)
        select.select_by_index(index)

    def save_btn(self):
        """点击保存按钮"""
        self.driver.find_element(*self.save_locator).click()

    def add_module_tips(self):
        """获取添加组件成功信息提示"""
        return self.driver.find_element(*self.success_tips_locator).text

    def click_more(self):
        """点击更多"""
        self.driver.find_element(*self.more_locator).click()

    def click_log(self):
        """点击日志"""
        self.driver.find_element(*self.log_locator).click()

    def click_admin(self):
        """点击头像，弹出下拉框"""
        self.driver.find_element(*self.admin_locator).click()

    def click_operate_log(self):
        """点击操作日志"""
        self.driver.find_element(*self.operation_log_locator).click()

    def click_poverty(self):
        """点击权限分配"""
        self.driver.find_element(*self.poverty_locator).click()

    def click_organization(self):
        """点击组织架构"""
        self.driver.find_element(*self.organization_locator).click()

    def click_person_data(self):
        """点击个人资料"""
        self.driver.find_element(*self.personal_data_locator).click()

    def click_message(self):
        """点击站内信"""
        self.driver.find_element(*self.message_locator).click()



